//
//  ActivityStatisticsCollectionViewCell.swift
//  MoodDiary
//
//  Created by OVIX on 2020/12/11.
//

import UIKit

class ActivityStatisticsCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var imgV: UIImageView!
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var titleLabel: UILabel!
    
    var dic: [String: Int]? {
        didSet {
            imgV.image = UIImage(named: dic?.keys.first ?? "")
            label.text = "\(dic?.values.first ?? 0)"
            titleLabel.text = dic?.keys.first
            
            let imageText = dic?.keys.first ?? ""
            if let showImg = UIImage(named: imageText) {
                imgV.image = showImg
            } else {
                if var imgArray = UserDefaults.standard.array(forKey: KUSERActiveImagesArrName) as? [[String:Any]] {
                    if let deletedImgArray = UserDefaults.standard.array(forKey: KUSERActiveDeletedImagesArrName) as? [[String:Any]] {
                        imgArray.append(contentsOf: deletedImgArray)
                    }
                    let imageName = imgArray.first(where: { $0["text"] as! String == imageText })?["imgName"] as? String ?? ""
                    imgV.image = UIImage(named: imageName)
                }
            }
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }

    override func layoutSubviews() {
        
        label.layer.cornerRadius = label.height * 0.5
        label.layer.masksToBounds = true
        
    }
    
}
